package com.mycompany.project.client;

import com.google.gwt.user.client.Random;

public class GameData {
	private int [] data = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	//number = matched pair through shuffle routine, is set to match pair or tiger or croc once matched.
	private String [] images = {"images/pickme.png",
			"images/bird.png",
			"images/boats.png",
			"images/brom.png",
			"images/bull.png",
			"images/bus.png",
			"images/cat.png",
			"images/flower.png",
			"images/kangaroo.png",
			"images/koala.png",
			"images/lighthouse.png",
			"images/lightning.png",
			"images/mia.png",
			"images/mushroom.png",
			"images/rainbow.png",
			"images/road.png",
			"images/ship.png",
			"images/sunset.png",	
			"images/trees.png",
			"images/croc.png",
			"images/tiger.png"
			}; // put matching images here as url strings. 18 pairs
	private int pick = 0; //pick 0= no pick, number = first pick number
	private int player = 19; //player either 19 or 20
	private int player1=0; // player one's correct picks so far
	private int player2=0; // player two's correct picks so far
	
	public GameData(){	
	}
	
	public int getPlayer1() {
		return player1;
	}

	public void setPlayer1(int player1) {
		this.player1 = player1;
	}
	
	public void incPlayer1(){
		this.player1++;
	}
	
	public void incPlayer2(){
		this.player2++;
	}

	public int getPlayer2() {
		return player2;
	}

	public void setPlayer2(int player2) {
		this.player2 = player2;
	}

	public int getPick() {
		return pick;
	}

	public void setPick(int pick) {
		this.pick = pick;
	}
	
	public void resetPick(){
		this.pick=0;
	}

	public int getPlayer() {
		return player;
	}

	public void setPlayer(int player) {
		this.player = player;
	}
	
	public void swapPlayer(){
		if (getPlayer()==19){
			this.player=20;
		}else{
			this.player=19;
		}
	}

	public void resetData(){
		for (int i=1; i<37; i++){
			data[i]=0;
		}
		this.player1=0;
		this.player2=0;
		this.pick=0;
	}
	
	public int getData(int i){
		return data[i];
	}
	
	public void setData(int i, int j){
		data[i] = j;
	}
	
	public String getImage(int i){
		return images[i];
	}
	
	public void shuffle(){
		resetData();	
		boolean run=true;
		int index;
		for(int i=1; i<19; i++){
			for(int j=0; j<2; j++){
				index = Random.nextInt(35)+1;
				run=true;
				while(run){
					if(data[index]==0){
						data[index]= i;
						run= false;
					}
					index++;
					if(index>36){
						index=1;
					}
				}
			}
		}	
	}

}
